import math


# 列表推导式
def generate_nums(scope):
    temp = []
    for i in range(scope):
        temp.append(i)

    return temp


def is_prime(num):
    if num <= 1:
        return False

    if num != 2 and num % 2 == 0:
        return False

    mid_divison = int(math.sqrt(num)) + 1

    for i in range(3, mid_divison, 2):
        if num % i == 0:
            return False

    return True


nums = generate_nums(100)

# 通过列表推导式，找不1-100的质数
new_zhishu_nums = [i for i in nums if is_prime(i)]

print("1-100之间的所有质数为=", new_zhishu_nums)


# 带多个条件的列表推导式

nums = generate_nums(20)

new_nums = [num for num in nums if num % 2 == 0 if num % 3 == 0 if num % 4 == 0]
print("new_nums=", new_nums)

# 三元运算符

nums = generate_nums(100)
new_nums = ["及格" if num > 60 else "不及格" for num in nums]
print(new_nums, nums)
print(len(list(filter(lambda item: item == "及格", new_nums))))
